//
//  YZNetworkManager+TDTrade.m
//  YZMicroStock
//
//  Created by Lv.Dongdong on 16/11/9.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZClient+TDTrade.h"
#import "YZMConfigureModel.h"

@implementation YZNetworkManager (TDTrade)

- (void)td_fecthTradeRiskWithsuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                 failure: (void (^)(NSError *error))failure {
    
    [self.mainNetwork cq_noCachePOST:URL_FOR_FETCH_TD_CONFIGURE_DATA parameters:@{COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE}
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)fetchCurrentMarketWithSuccess:(void (^)(NSURLSessionDataTask *task,id responseObject))success
                         failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{COMMON_REQUEST_DEVICE: COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCacheGET: URL_FOR_FETCH_TD_CURRENT_MARKET parameters: params
                            success:^(NSURLSessionDataTask *task, id responseObject) {
                                if (success) {
                                    success(task, responseObject);
                                }
                            } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}


-(void)td_fetchSaleTradeListForDsuccess:(void (^)(NSURLResponse *, id))success failure:(void (^)(NSError *))failure
{
    NSDictionary *params = @{
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_SALE_TRADE_LIST_D  parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchSaleTradeListForDOfMemcachesuccess:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_SALE_TRADE_LIST_D_OF_MEMCACHE parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchTradeSettlementListForDWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize  withID:(NSInteger )schemeId success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,
                             @"schemeId":@(schemeId)};
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_TRADE_SETTLEMENT_LIST_D parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_createSchemeWithParams:(NSMutableDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    YZMConfigureModel *model = dic[@"model"];
    NSDictionary *params = @{@"money":dic[@"money"],
                             @"principal":dic[@"principal"],
                             @"deferCharge":dic[@"deferCharge"],
                             @"holdDays":dic[@"holdDays"],
                             @"quitLossRatio":@(model.quitLossRatio),
                             @"quitGainRatio":@(model.quitGainRatio),
                             @"deferConditionRatio":@(model.deferConditionRatio),
                             @"token":model.token,
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_CREATE_SCHEME parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_fetchTradeHistoryListForDWithPage:(NSInteger)page andPageSize:(NSInteger)pageSize  success:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{@"page":@(page),
                             @"pageSize":@(pageSize),
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCacheGET:URL_FOR_FETCH_TRADE_HISTORY_LIST parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
            
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchTradeStopListForsuccess:(void (^)(NSURLResponse *response,id responseObject))success failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE};
    [self.mainNetwork cq_noCacheGET:URL_FOR_STOP_TACK_LIST parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success(task.response, responseObject);
        }
    }failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

- (void)td_fetchAddMoneyInitWithParams:(NSDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"money":dic[@"money"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_ADD_MONEY_INIT parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
     if (success) {
             success(task, responseObject);
         }
     } failure:^(NSURLSessionDataTask *task, NSError *error) {
         if (failure) {
             failure(error);
         }
     }];
}

- (void)td_createStrategyWithParams:(NSMutableDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"schemeId":dic[@"ID"],
                             @"money":dic[@"money"],
                             @"serviceCharge":dic[@"chargePrice"],
                             @"volumeOrder":dic[@"amount"],
                             @"stockCode":dic[@"stockCode"],
                             @"useTip":dic[@"useTip"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_CREATE_STRATERY parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_confirmAddMoneyWithParams:(NSDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"lossPrincipal":dic[@"lossPrincipal"],
                             @"money":dic[@"money"],
                             @"deferCharge":dic[@"deferCharge"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_ADD_MONEY parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_applySettlementWithParams:(NSDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"schemeId":dic[@"id"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_APPLY_SETTLEMENT parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_addBondsMoneyWithParams:(NSDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"lossPrincipal":dic[@"lossPrincipal"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_ADD_BONDS_MONEY parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_fetchRenewalInitWithParams:(NSDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"holdDays":dic[@"holdDays"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_ADD_RENEWAL_INIT parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_addSchemeRenewalInitWithParams:(NSDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure {
    
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"lossPrincipal":dic[@"lossPrincipal"],
                             @"diffBalance":dic[@"diffBalance"],
                             @"holdDays":dic[@"holdDays"],
                             @"deferCharge":dic[@"deferCharge"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_ADD_SCHEME_RENEWAL parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}


- (void)td_StopGiveUpWithParams:(NSMutableDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"isTakeOver":dic[@"isTakeOver"],
                             @"lossPrincipal":dic[@"lossPrincipal"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_STOP_TACK_OVER parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

- (void)td_StopBuyOverWithParams:(NSMutableDictionary *)dic success:(void (^)(NSURLSessionDataTask *task,id responseObject))success failure: (void (^)(NSError *error))failure
{
    NSDictionary *params = @{@"id":dic[@"id"],
                             @"isTakeOver":dic[@"isTakeOver"],
                             @"lossPrincipal":dic[@"lossPrincipal"],
                             COMMON_REQUEST_DEVICE:COMMON_REQUEST_DEVICE_VALUE,};
    [self.mainNetwork cq_noCachePOST:URL_FOR_STOP_TACK_OVER parameters:params
                             success:^(NSURLSessionDataTask *task, id responseObject) {
                                 if (success) {
                                     success(task, responseObject);
                                 }
                             } failure:^(NSURLSessionDataTask *task, NSError *error) {
                                 if (failure) {
                                     failure(error);
                                 }
                             }];
}

-(void)td_GetDeferDataWithdic:(NSMutableDictionary *)dic Success:(void (^)(NSURLSessionDataTask *, id))success failure:(void (^)(NSError *))failure
{
    NSDictionary *params = @{@"id":dic[@"id"],
                             COMMON_REQUEST_DEVICE: COMMON_REQUEST_DEVICE_VALUE};
    
    [self.mainNetwork cq_noCacheGET: URL_FOR_GET_DEFER_DATA parameters: params
                            success:^(NSURLSessionDataTask *task, id responseObject) {
                                if (success) {
                                    success(task, responseObject);
                                }
                            } failure: ^(NSURLSessionDataTask *task, NSError *error) {
                                if (failure) {
                                    failure(error);
                                }
                            }];
}


@end
